<template>
	<div>
		<el-dialog title="选择发布的班级" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
			<el-select v-model="classid" multiple collapse-tags style="margin-left: 20px;" placeholder="请选择">
				<el-option v-for="item in options" :key="item.id" :label="item.className" :value="item.id">
				</el-option>
			</el-select>
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="creatCourse()">确 定</el-button>
			</span>
		</el-dialog>
		<div class="main">
			<div style="margin-left: 1.25rem;">返回</div>
			<div style="font-size: 1.25rem;font-weight: 18.75;">发布任务</div>
			<div style="height: 3.25rem;width: 3.25rem;margin-right: 1.25rem;" @click="$router.push('/ReleaseTest')"></div>
		</div>
		<el-form ref="form" :model="form" label-width="100px" style="width: 80%;margin-left: 10%;margin-top: 1.25rem;margin-right: 10%;">
			<!-- <el-form-item label="发布的班级" style="margin-top: 1.25rem;">
				<el-select v-model="value2" multiple collapse-tags placeholder="请选择">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item> -->

			<el-form-item label="开始时间" style="margin-top: 0.625rem;">
				<div class="block">
					<el-date-picker v-model="startTime" type="datetime" placeholder="选择日期时间" align="right" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;" :picker-options="pickerOptions0">
					</el-date-picker>
				</div>
			</el-form-item>
			<el-form-item label="截止时间">
				<div class="block">
					<el-date-picker v-model="closeTime" type="datetime" placeholder="选择日期时间" align="right" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;" :picker-options="pickerOptions0">
					</el-date-picker>
				</div>
			</el-form-item>
			<el-form-item label="作业名称">
				<el-input v-model="taskName" style="width: 100%;"></el-input>
			</el-form-item>
			<el-form-item label="允许学生补交">
				<el-switch v-model="submitAfterEnd">允许学生补交</el-switch>
			</el-form-item>

			<el-form-item label="及格标准">
				<el-input style='width: 90%;' v-model="passingScore" ></el-input>
				<span style="color:#606266">分</span>
			</el-form-item>
			<el-form-item label="重做设置">
				<el-checkbox-group v-model="form.advancedsetting">
					
					<el-form-item style="display: flex;">
						<el-input style='width:80px' v-model="redoTimesAllowed"></el-input>
						<div>次</div>
					</el-form-item>

					<div></div>
				</el-checkbox-group>
			</el-form-item>

			<el-form-item label="防作弊">
				<el-checkbox-group v-model="entitrick">
					<div></div>
					<el-checkbox label="1" name="scoreSetting">允许学生查看分数</el-checkbox>
					<div></div>
					<el-checkbox label="2" name="isShowTheAnswer">允许学生查看答案</el-checkbox>
					<div></div>
					<el-checkbox label="3" name="isPasteAllowed">允许学生粘贴答案</el-checkbox>
					<div></div>
					<el-checkbox label="4" name="showTheAnswerAfterReview">批阅后是否允许查看答案 </el-checkbox>
					<div></div>
					<el-checkbox label="5" name="isOutOfOrder">题目乱序</el-checkbox>
					<el-checkbox label="6" name="redoTimesAllowed">
						<div>作业截止前允许学生重做</div>
					
					</el-checkbox>
					<div></div>
					<div class='section-description'>学生接收到的题目显示顺序不同</div>

					<div></div>
				</el-checkbox-group>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="onSubmit">立即创建</el-button>
				<el-button>取消</el-button>
			</el-form-item>

		</el-form>
	</div>
</template>

<script>
	import {
		HttpManager
	} from "../../../../request/Teacher.js"
	export default {
		data() {
			return {
				form: {
					data1: '',
					data2: '',
					passingstandard: '',
					advancedsetting: [],
					remaketime: '',
					entitrick: [],
					status: '',
					randomnumber: '',
					urge: [],
					urgetime: '',
					requirement: [],
					requirementpoint: '',
					scoresetting: [],



				},
				entitrick: [],
				taskName: '',
				startTime: '',
				courseId: '',
				isOutOfOrder:0,
				isPasteAllowed:0,
				closeTime: '',
				submitAfterEnd: 0,
				passingScore: '',
				redoTimesAllowed:0,
				dialogVisible:false,
				courseID:localStorage.getItem("ClassId"),
				options:[],
				examId:'',
				classid:[],
				scoreSetting:0,
				isShowTheAnswer:0,
				showTheAnswerAfterReview:0,
				pickerOptions0: {
					disabledDate(time) {
						return time.getTime() < Date.now();
					}
				},
			}
		},
		methods: {
			onSubmit() {
				for (let i = 0; i < this.entitrick.length; i++) {
					if (this.entitrick[i] == 1) {
						this.scoreSetting = 1;
					}
					if (this.entitrick[i] == 2) {
						this.isShowTheAnswer = 1;
					}
					if (this.entitrick[i] == 3) {
						this.isPasteAllowed = 1;
					}
					if (this.entitrick[i] == 4) {
						this.showTheAnswerAfterReview = 1;
					}
					if (this.entitrick[i] == 5) {
						this.isOutOfOrder = 1;
					}
					if (this.entitrick[i] == 6) {
						this.redoTimesAllowed = 1;
					}
				}
				if(this.submitAfterEnd)
				{
					this.submitAfterEnd=1;
				}else{
					this.submitAfterEnd=0;
				}
				var parmas = {
					closeTime: this.closeTime,
					beforeEndTime: this.closeTime,
					courseId: localStorage.getItem("ClassId"),
					isOutOfOrder: 1,
					isPasteAllowed: this.isPasteAllowed,
					isShowTheAnswer: this.isShowTheAnswer,
					passingScore: this.passingScore,
					redoTimesAllowed: 1,
					scoreSetting: this.scoreSetting,
					showTheAnswerAfterReview:this.showTheAnswerAfterReview,
					startTime:this.startTime,
					submitAfterEnd: this.submitAfterEnd,
					taskName: this.taskName,
					testPaperId: localStorage.getItem("TestId")
				}
				HttpManager.creatTask(parmas).then(e => {
					console.log(e);
					this.examId=e.data.data.id;
					this.dialogVisible=true
				})
			},
			//获取班级列表
			getClazzByCourseId() {
				var parmas = {
					courseId: this.courseID
				}
				HttpManager.getClazzByCourseId(this.qs.stringify(parmas)).then(e => {
					console.log(e);
					this.options = e.data.data;
				})

			},
			handleClose()
			{
				this.dialogVisible=false
			},
			creatCourse()
			{
				this.dialogVisible = false;
				var clazzIds=this.classid;
				HttpManager.addTaskToClazz(this.examId,clazzIds).then(e=>{
					console.log(e);
					this.$message({
						message: '发布成功',
						type: 'success'
					});
					this.$router.push('/work');
				})
				
			},
		},
		created() {
			this.getClazzByCourseId();
		}
	}
</script>

<style scoped="scoped">
	.section-description {
		font-size: 10px;
		color: #C0C4CC;
		margin-left: 25px;
	}

	.main {
		width: 100%;
		height: 3.25rem;
		line-height: 3.25rem;
		display: flex;
		justify-content: space-between;
		color: white;
		text-align: center;
		cursor: pointer;
		background-color: #03d3bd;
		/* position: fixed; */
		overflow: hidden;
	}
</style>
